package com.yt.system.controller;


import com.yt.system.domain.Objective;
import com.yt.system.domain.ObjectiveKeyresults;
import com.yt.system.service.ObjectiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("O")
@RequestMapping("/objective")
@RestController
public class ObjectiveController {
    @Autowired
    ObjectiveService objectiveService;

    //根据uid查询个人okr
    @ApiOperation(value = "根据uid查询个人okr")
    @RequestMapping(value = "/getOkr/{uid}",method = RequestMethod.GET)
//    @GetMapping("/getOkr/{uid}")
    @ResponseBody
    public List<ObjectiveKeyresults> selectOkr(@PathVariable("uid") int uid){
        return objectiveService.selectOkr(uid);
    }

    //form-data提交，更新
    @ApiOperation(value = "修改OKR")
    @RequestMapping(value = "/updateObjective",method = RequestMethod.POST)
    public int updateObjective(Objective obj){
        return objectiveService.UpdO(obj);
    }

    //    json数据类型提交，插入
    @ApiOperation(value = "添加OKR")
    @RequestMapping(value = "/addObjective", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public int addObjective(@RequestBody Objective obj){
        return objectiveService.InsO(obj);
    }

    //删除
    @ApiOperation(value = "删除OKR")
    @RequestMapping(value = "deleteObjectives/{id}",method = RequestMethod.GET)
    public int DeleteObjective(@PathVariable int id){
        return objectiveService.DelO(id);
    }

    @ApiOperation(value = "优秀OKR 默认为0,1为优秀")
    @RequestMapping(value = "/updExcellent",method = RequestMethod.POST)
    public int updateExcellentOkr(Objective obj){
        return objectiveService.UpdExcellentOkr(obj);
    }

    @ApiOperation(value = "OKR评论")
    @RequestMapping(value = "/updComment",method = RequestMethod.POST)
    public int updateComment(Objective obj){
        return objectiveService.UpdComment(obj);
    }


}
